package com.hy.common.excel;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hy.common.utils.MyObjectUtils;
import com.hy.entity.dto.HyPropertySearchDTO;
import com.hy.entity.dto.PlaceSearchDTO;
import com.hy.entity.dto.ProperSortDTO;
import com.hy.entity.pojo.HyPlace;
import com.hy.entity.pojo.HyPropertySort;
import com.hy.entity.vo.HyPlaceVO;
import com.hy.entity.vo.HyPropertySortVO;
import com.hy.mapper.HyPropertySortMapper;
import com.hy.service.HyPropertySortService;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Component
public class HyPropertySortExport extends AbstractExcelExport<HyPropertySortVO>{

    private Integer count=0;
    @Resource
    private HyPropertySortMapper sortMapper;
    @Resource
    private HyPropertySortService sortService;

    public void exportWithBigData(HttpServletResponse response, String fileName, ProperSortDTO searchDTO){

        this.count=sortMapper.selectCount(new LambdaQueryWrapper<HyPropertySort>().and(wapper->
                wapper.eq(!ObjectUtils.isEmpty(searchDTO.getUnitId()),HyPropertySort::getUnitId,searchDTO.getUnitId())
                        .eq(MyObjectUtils.isNotBlank(searchDTO.getSortName()),HyPropertySort::getSortName,searchDTO.getSortName())
                        .eq(!ObjectUtils.isEmpty(searchDTO.getSortMgr()),HyPropertySort::getSortMgr,searchDTO.getSortMgr()  )
                        .eq(HyPropertySort::getDel,searchDTO.getDel())
        )).intValue();
        this.exportWithBigData(response, fileName, null, BeanUtil.beanToMap(searchDTO), HyPropertySortVO.class);
    }

    @Override
    protected Integer dataTotalCount(Map<String, Object> queryCondition) {
        return this.count;
    }


    @Override
    protected Integer eachSheetTotalCount() {//每一个sheet存放的数据总数
        return 500000;
    }

    @Override
    protected Integer eachTimesWriteSheetTotalCount() {//每次写入sheet的总数
        return 5000;
    }
    @Override
    protected void buildDataList(List<HyPropertySortVO> resultList, Map<String, Object> queryCondition, Integer pageNo, Integer pageSize) {
        for (HyPropertySortVO hyPropertySortVO : sortService.listPage(queryCondition, pageNo, pageSize)) {
            resultList.add(hyPropertySortVO);
        }

//        if(CollUtil.isNotEmpty(entityDoList)){
//            entityDoList.forEach(item -> {
//                resultList.add(Arrays.asList(
//                        item.getSortId().toString(),item.getSortName(),item.getUnitName(),item.getMgrName()
//                        ,item.getCode(),item.getCreateDate().toString()
//                ));
////                resultList.add(Arrays.asList(String.valueOf(item.getId()),String.valueOf(item.getEmpno()),String.valueOf(item.getEname()),item.getJob(),String.valueOf(item.getMgr()),String.valueOf(item.getDeptno())));
//            });
//        }


    }
}
